package com.zsrt.java.day20170111.lh.homework.demo01;


import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.junit.Test;

/**
 * 2017-01-11
 * 报表：
*本月有多少天
*本年有多少天
*本月的最后一天是哪一天
*下个月的第一天
*下个月的最后一天
 * 
 * @author My
 *
 */
public class Report {

	
	@Test
	public void testName() throws Exception {
		
		
		
		
		//实例
		Calendar cal = Calendar.getInstance();
		
		//本月有多少天
		int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		
		//本年有多少天
		int maxYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
		
		System.out.println("本月有多少天："+maxDay);
		System.out.println("本年有多少天："+maxYear);
		
		//本月的最后一天是哪一天
		cal.set( cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), maxDay);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String gtime = sdf.format(cal.getTime());
		System.out.println("这个月最后一天："+gtime);
		
		//下个月的第一天
		cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1,1);
		String nextM=sdf.format(cal.getTime());
		System.out.println("下个月第一天："+nextM);
		
		//下个月的最后一天
		int netMaxDay=cal.getActualMaximum(Calendar.DAY_OF_MONTH);
		cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),netMaxDay);
		String nextMm=sdf.format(cal.getTime());
		System.out.println("下个月最后一天："+nextMm);
		
		
		//回滚一天/一年
		cal.roll(Calendar.YEAR, +1);
		cal.roll(Calendar.DATE, -1);
		
		

		
	 
	 
	 
		

		
		
		
		
	}
}
